package com.ss.project.xia17user.config.security;


import org.springframework.stereotype.Service;
import java.util.Arrays;

/**
 * 权限检测
 * @author xia17
 * @date 2020/8/6 16:32
 */
@Service("spc")
public class SecurityPermissionCheck {

    /**
     * 包含所有
     * @param permissions 权限信息
     * @return /
     */
    public Boolean hasAll(String... permissions){
        return Arrays.stream(permissions)
                .allMatch(SecurityUtils.getAuthorities()::contains);
    }

    /**
     * 包含一个
     * @param permissions 权限信息
     * @return /
     */
    public Boolean hasOne(String... permissions){
        return Arrays.stream(permissions)
                .anyMatch(SecurityUtils.getAuthorities()::contains);
    }

    /**
     * 不能包含所有
     * @param permissions 权限信息
     * @return /
     */
    public Boolean notHasAll(String... permissions){
        return !Arrays.stream(permissions)
                .allMatch(SecurityUtils.getAuthorities()::contains);
    }

    /**
     * 不能包含其中一个
     * @param permissions 权限信息
     * @return /
     */
    public Boolean notHasOne(String... permissions){
        return Arrays.stream(permissions)
                .noneMatch(SecurityUtils.getAuthorities()::contains);
    }

}
